class EXAMPLE6
-- This example show how use a progress bar with a timer.

inherit
	IUP_INTERFACE

create {ANY}
   make

feature {ANY}

	pb: IUP_PROGRESS_BAR
	counter: INTEGER
	tm: IUP_TIMER

	make
		local
			bt: IUP_BUTTON
			a: ARRAY[IUP_WIDGET]
			vb: IUP_VBOX
			i: STRING
			w: IUP_DIALOG
			gui: IUP
		do
			gui := iup_open
			
			create pb.progress_bar

			create tm.timer
         tm.set_cb_action(agent crono)
			tm.set_time(100)
			
	      create bt.button("Starts")
			bt.set_cb_action(agent bar)
			
			a := {ARRAY[IUP_WIDGET]} << pb, bt >>

	      create vb.vbox(a)
	      vb.set_alignment("ACENTER")
			vb.set_gap(10)
			vb.set_margin(10, 10)
			
	      create w.dialog(vb)
			w.set_title("Progress bar")
			w.set_cb_close(agent close)
	      i := w.show

         gui.main_loop
			gui.close
		end

	bar (widget: IUP_BUTTON): STRING
		do
			-- These three lines are used to return the progress bar to 
			-- 0, if the user press the button again. But of course, 
			-- these are not always necessary.
			counter := 0

			pb.set_value((0).to_double)
			tm.start

			Result := "IUP_DEFAULT"
		end

	crono (t: IUP_TIMER): STRING
		local
			r: REAL_64
		do
			r := counter.to_double / (10).to_double
			
			io.put_double(r)
			io.put_new_line

			pb.set_value(r)

			counter := counter + 1 -- Update the counter.

			if counter > 10 then
				t.stop
			end

			Result := "IUP_DEFAULT"
		end

	close (dl: IUP_DIALOG): STRING
		do
			tm.destroy
			
			Result := "IUP_CLOSE"
		end

end

